package org.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.example.pojo.entity.ApUser;
import org.example.mapper.ApUserMapper;
import org.example.service.ApUserService;
import org.springframework.stereotype.Service;

/**
 * @author 妖妖零
 * @description 针对表【ap_user(APP用户信息表)】的数据库操作Service实现
 * @createDate 2024-06-06 16:58:27
 */
@Service
public class ApUserServiceImpl extends ServiceImpl<ApUserMapper, ApUser>
        implements ApUserService {


    /**
     * 分页获取用户数据
     *
     * @param page
     * @param size
     * @param userName
     * @param phonenumber
     * @param status
     * @param startTime
     * @param endTime
     * @return
     */
    @Override
    public Page<ApUser> pageList(Integer page, Integer size, String userName, String phonenumber, String status, String startTime, String endTime) {
        Page<ApUser> pages = new Page<>(page, size);
        LambdaQueryWrapper<ApUser> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNoneBlank(userName)) {
            wrapper.like(ApUser::getName, userName);
        }
        if (StringUtils.isNoneBlank(phonenumber)) {
            wrapper.like(ApUser::getPhone, phonenumber);
        }
        if (StringUtils.isNoneBlank(status)) {
            wrapper.eq(ApUser::getStatus, status);
        }
        if (StringUtils.isNoneBlank(startTime) && StringUtils.isNoneBlank(endTime)) {
            wrapper.between(ApUser::getCreatedTime, startTime, endTime);
        }
        Page<ApUser> userPage = baseMapper.selectPage(pages, wrapper);

        return userPage;

    }

    @Override
    public void status(Integer userId, Integer status) {
        ApUser apUser = new ApUser();
        apUser.setId(userId);
        apUser.setStatus(status);
        baseMapper.updateById(apUser);
    }
}




